/*
 * This file is part of aion-unique <aion-unique.org>.
 *
 *  aion-unique is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  aion-unique is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with aion-unique.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.aionemu.gameserver.model.templates.goods;

import gnu.trove.TIntObjectHashMap;

import java.util.List;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

/**
 * 
 * @author ATracer
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "GoodsList", propOrder = {
    "item", "itemMap"
})
public class GoodsList
{
	protected List<GoodsList.Item>	item;
	@XmlAttribute(required = true)
	protected int					id;
	@XmlAttribute
	protected int				guildLvl;

	private TIntObjectHashMap<GoodsList.Item>	itemMap	= new TIntObjectHashMap<GoodsList.Item>();

	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		if (item == null)
			return;
		for (GoodsList.Item items : item)
			itemMap.put(items.getProduction(), items);
		item.clear();
		item = null;
	}

	public Object[] getItemList()
	{
		return itemMap.getValues();
	}

	public Item getItem(int itemId)
	{
		return itemMap.get(itemId);
	}
	/**
	 * Gets the value of the id property.
	 * 
	 */
	public int getId()
	{
		return id;
	}

	/**
	 * Gets the value of the guildLvl property.
	 * 
	 * @return
	 *     possible object is
	 *     {@link Integer }
	 *     
	 */
	public int getGuildLvl()
	{
		return guildLvl;
	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlType(name = "", propOrder =
	{ "ingredient" })
	public static class Item
	{

		@XmlElement(required = true)
		protected List<Ingredient>	ingredient;
		@XmlAttribute(required = true)
		protected int				production;

		public List<Ingredient> getIngredient()
		{
			return this.ingredient;
		}

		/**
		 * Gets the value of the production property.
		 * 
		 */
		public int getProduction()
		{
			return production;
		}

	}
}
